package com.ruoyi.web.controller.youxuan;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YouxuanGoodsPreferential;
import com.ruoyi.system.service.IYouxuanGoodsPreferentialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品优惠管理Controller
 * 
 * @author ruoyi
 * @date 2021-01-03
 */
@RestController
@RequestMapping("/youxuan/goods_preferential")
public class YouxuanGoodsPreferentialController extends BaseController
{
    @Autowired
    private IYouxuanGoodsPreferentialService youxuanGoodsPreferentialService;

    /**
     * 查询商品优惠管理列表
     */
    @PreAuthorize("@ss.hasPermi('youxuan:goods_preferential:list')")
    @GetMapping("/list")
    public TableDataInfo list(YouxuanGoodsPreferential youxuanGoodsPreferential)
    {
        startPage();
        List<YouxuanGoodsPreferential> list = youxuanGoodsPreferentialService.selectYouxuanGoodsPreferentialList(youxuanGoodsPreferential);
        return getDataTable(list);
    }

    /**
     * 导出商品优惠管理列表
     */
    @PreAuthorize("@ss.hasPermi('youxuan:goods_preferential:export')")
    @Log(title = "商品优惠管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(YouxuanGoodsPreferential youxuanGoodsPreferential)
    {
        List<YouxuanGoodsPreferential> list = youxuanGoodsPreferentialService.selectYouxuanGoodsPreferentialList(youxuanGoodsPreferential);
        ExcelUtil<YouxuanGoodsPreferential> util = new ExcelUtil<YouxuanGoodsPreferential>(YouxuanGoodsPreferential.class);
        return util.exportExcel(list, "goods_preferential");
    }

    /**
     * 获取商品优惠管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('youxuan:goods_preferential:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(youxuanGoodsPreferentialService.selectYouxuanGoodsPreferentialById(id));
    }

    /**
     * 新增商品优惠管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:goods_preferential:add')")
    @Log(title = "商品优惠管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YouxuanGoodsPreferential youxuanGoodsPreferential)
    {
        return toAjax(youxuanGoodsPreferentialService.insertYouxuanGoodsPreferential(youxuanGoodsPreferential));
    }

    /**
     * 修改商品优惠管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:goods_preferential:edit')")
    @Log(title = "商品优惠管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YouxuanGoodsPreferential youxuanGoodsPreferential)
    {
        return toAjax(youxuanGoodsPreferentialService.updateYouxuanGoodsPreferential(youxuanGoodsPreferential));
    }

    /**
     * 删除商品优惠管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:goods_preferential:remove')")
    @Log(title = "商品优惠管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody YouxuanGoodsPreferential youxuanGoodsPreferential)
    {
        return toAjax(youxuanGoodsPreferentialService.deleteYouxuanGoodsPreferential(youxuanGoodsPreferential));
    }
}
